package com.ruoyi.yuangong.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yuangong.domain.PaibanReturn;
import com.ruoyi.yuangong.domain.Paibangaunli;
import com.ruoyi.yuangong.domain.Vpaiban;
import com.ruoyi.yuangong.service.IPaibangaunliService;
import com.ruoyi.yuangong.service.IVpaibanService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * paibanController
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Controller
@RequestMapping("/yuangong/paiban")
public class PaibangaunliController extends BaseController {
    private final String prefix = "yuangong/paiban";

    @Autowired
    private IPaibangaunliService paibangaunliService;

    @Autowired
    private IVpaibanService vpaibanService;

    @RequiresPermissions("yuangong:paiban:view")
    @GetMapping()
    public String paiban () {
        return prefix + "/paiban";
    }

    /**
     * 查询paiban列表
     */
    @RequiresPermissions("yuangong:paiban:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list (Vpaiban vpaiban) {
        startPage();
        List<Vpaiban> list = vpaibanService.selectVpaibanList(vpaiban);
        return getDataTable(list);
    }

    /**
     * 导出paiban列表
     */
    @RequiresPermissions("yuangong:paiban:export")
    @Log(title = "paiban", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export (Paibangaunli paibangaunli) {
        List<Paibangaunli> list = paibangaunliService.selectPaibangaunliList(paibangaunli);
        ExcelUtil<Paibangaunli> util = new ExcelUtil<Paibangaunli>(Paibangaunli.class);
        return util.exportExcel(list, "paiban数据");
    }

    /**
     * 新增paiban
     */
    @GetMapping("/add")
    public String add () {
        return prefix + "/add";
    }

    /**
     * 新增保存paiban
     */
    @RequiresPermissions("yuangong:paiban:add")
    @Log(title = "paiban", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave (Paibangaunli paibangaunli) {
        return toAjax(paibangaunliService.insertPaibangaunli(paibangaunli));
    }

    /**
     * 修改paiban
     */
    @RequiresPermissions("yuangong:paiban:edit")
    @GetMapping("/edit/{id}")
    public String edit (@PathVariable("id") Integer id, ModelMap mmap) {
        PaibanReturn paibangaunli = paibangaunliService.selectPaibanReturnById(id);
        mmap.put("paibangaunli", paibangaunli);
        return prefix + "/edit";
    }

    /**
     * 修改保存paiban
     */
    @RequiresPermissions("yuangong:paiban:edit")
    @Log(title = "paiban", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave (PaibanReturn paibangaunli) {
        return toAjax(paibangaunliService.updatePaibangaunli(paibangaunli));
    }

    /**
     * 删除paiban
     */
    @RequiresPermissions("yuangong:paiban:remove")
    @Log(title = "paiban", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove (String ids) {
        return toAjax(paibangaunliService.deletePaibangaunliByIds(ids));
    }
}
